﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using EMS.Calendar.Models;
using System.Web.Mvc;

namespace EMS.Calendar.Services {
    public class CalendarService : ICalendarService {

        public IEnumerable<SelectListItem> GetEventOccurrenceList(EventOccurrenceType selected = EventOccurrenceType.Single) {
            IEnumerable<SelectListItem> eventOccurrenceList;

            eventOccurrenceList = Enum.GetValues(typeof(EventOccurrenceType)).Cast<EventOccurrenceType>()
                .Select(val => new SelectListItem {
                    Value = val.ToString(),
                    Text = val.ToString(),
                    Selected = val == selected,
                });

            return eventOccurrenceList;
        }

        public IEnumerable<SelectListItem> GetPatternList(PatternType selected = PatternType.Daily) {
            IEnumerable<SelectListItem> patternList;

            patternList = Enum.GetValues(typeof(PatternType)).Cast<PatternType>()
                .Select(val => new SelectListItem {
                    Value = val.ToString(),
                    Text = val.ToString(),
                    Selected = val == selected,
                });

            return patternList;
        }

        public IEnumerable<SelectListItem> GetDayInstanceList(DayInstanceType selected = DayInstanceType.first) {
            IEnumerable<SelectListItem> dayInstanceList;

            dayInstanceList = Enum.GetValues(typeof(DayInstanceType)).Cast<DayInstanceType>()
                .Select(val => new SelectListItem {
                    Value = val.ToString(),
                    Text = val.ToString(),
                    Selected = val == selected,
                });

            return dayInstanceList;
        }

        public IEnumerable<SelectListItem> GetDayNameList(List<DayNameType> selected = null) {
            if (selected == null) {
                selected = new List<DayNameType>();
            }
            IEnumerable<SelectListItem> dayNameList;

            dayNameList = Enum.GetValues(typeof(DayNameType)).Cast<DayNameType>()
                .Select(val => new SelectListItem {
                    Value = val.ToString(),
                    Text = val.ToString(),
                    Selected = selected.Contains(val),
                });

            return dayNameList;
        }

        public IEnumerable<SelectListItem> GetMonthNameList(MonthNameType selected = MonthNameType.January) {
            IEnumerable<SelectListItem> monthNameList;

            monthNameList = Enum.GetValues(typeof(MonthNameType)).Cast<MonthNameType>()
                .Select(val => new SelectListItem {
                    Value = val.ToString(),
                    Text = val.ToString(),
                    Selected = val == selected,
                });

            return monthNameList;
        }

        public IEnumerable<SelectListItem> GetRecurrenceEndList(RecurrenceEndType selected = RecurrenceEndType.None) {
            IEnumerable<SelectListItem> recurrenceEndList;

            recurrenceEndList = Enum.GetValues(typeof(RecurrenceEndType)).Cast<RecurrenceEndType>()
                .Select(val => new SelectListItem {
                    Value = val.ToString(),
                    Text = val.ToString(),
                    Selected = val == selected,
                });

            return recurrenceEndList;
        }
    }
}